﻿using System.Security.Cryptography;

namespace B.S.BasicData.Api.Read.Extensions
{
    public static class StringExtension
    {

        /// <summary>
        /// 生成一个随机盐值（默认16位）
        /// </summary>
        /// <param name="o"></param>
        /// <param name="size">salt长度</param>
        /// <returns></returns>
        public static string GenerateSalt(this object o, int size = 16)
        {
            using (var rng = RandomNumberGenerator.Create())
            {
                var saltBytes = new byte[size];
                rng.GetBytes(saltBytes);
                return Convert.ToBase64String(saltBytes);
            }
        }
    }
}